package com.gonsin.gview.logic.utils;

import cn.hutool.core.convert.impl.BooleanConverter;
import cn.hutool.core.convert.impl.PrimitiveConverter;
import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.converters.DateTimeConverter;

import java.util.Date;

public class MyBooleanConverter extends BooleanConverter implements Converter {

    @Override
    protected Boolean convertInternal(Object value) {
        if(value == null){
            return null;
        }
        if(Boolean.class == value.getClass()){
            return (boolean) value;
        }
        String valueStr = convertToStr(value);
        return Boolean.valueOf(valueStr);
    }

    @Override
    public <T> T convert(Class<T> type, Object value) {
        if(value == null){
            return null;
        }
        if(Boolean.class == value.getClass()){
            return (T) value;
        }
        String valueStr = convertToStr(value);
        return (T) Boolean.valueOf(valueStr);
    }
}
